function avg_acc = test_gogo_adaboost_svm_brute_force_and_hellinger(X1train, X2train, ytrain, gidtrain)
% test_gogo_boost_brute_force_histograms - tests 3-fold avg for adaboost 
% running adaboost on 7 different runs of brute force SVM (the 7 'weak 
% learners').
    avg_acc = 0;
    %cnt = 0;
    for gid=1:3
        % generate test 
        % Brute force
        [tr_data, tr_label, te_data, te_label] = gen_splitted_data_brute_force(X1train, X2train, ytrain, gidtrain, gid);        
               
        % for L1
        norm_type = 'L1';
        [tr_data_l1, tr_label_l1, te_data_l1, te_label_l1] = ...
                gen_splitted_data(X1train, X2train, ytrain, gidtrain, ...
                                  gid, norm_type);
        % for hellinger
        norm_type = 'hellinger';   
        [tr_data_hellinger, tr_label_hellinger, te_data_hellinger, te_label_hellinger] = ...
                gen_splitted_data(X1train, X2train, ytrain, gidtrain, ...
                                  gid, norm_type);                                                           
        
        
        % normalize the data to [-1,1]. Test is normalized according to
        % train data.
        [tr_data, norm_params] = norm_data_brute_force(tr_data);
        [te_data, ~] = norm_data_brute_force(te_data, norm_params);                             
                              
         %L1
        [tr_data_l1, norm_params] = norm_data(tr_data_l1);
        te_data_l1= norm_data(te_data_l1, norm_params);
        
        [tr_data_hellinger, norm_params] = norm_data(tr_data_hellinger);
        te_data_hellinger= norm_data(te_data_hellinger, norm_params);
        
        
 % Train SVMs
% Polynomial Kernel of degree 4
C_param = 1000;
gamma_param = 0.01;
coef0_param = 1;
degree_param = 4;
kernel_param = 1; 
% Brute force
model = train_svm(tr_data, tr_label, te_data, te_label, kernel_param, C_param, gamma_param, coef0_param, degree_param);
[train_results_1, ~, ~] = svmpredict(tr_label, tr_data, model, '');
[test_results_1, ~, ~] = svmpredict(te_label, te_data, model, '');

% L1 norm
model = train_svm(tr_data_l1, tr_label_l1, te_data_l1, te_label_l1, kernel_param, C_param, gamma_param, coef0_param, degree_param);
[train_results_2, ~, ~] = svmpredict(tr_label_l1, tr_data_l1, model, '');
[test_results_2, ~, ~] = svmpredict(te_label_l1, te_data_l1, model, '');


model = train_svm(tr_data_hellinger, tr_label_hellinger, te_data_hellinger, te_label_hellinger, kernel_param, C_param, gamma_param, coef0_param, degree_param);      
[train_results_3, ~, ~] = svmpredict(tr_label_hellinger, tr_data_hellinger, model, '');
[test_results_3, ~, ~] = svmpredict(te_label_hellinger, te_data_hellinger, model, '');



% Radial Kernel 
C_param = 1000;
gamma_param = 0.01;
kernel_param = 2;

model = train_svm(tr_data, tr_label, te_data, te_label, kernel_param, C_param, gamma_param, coef0_param, degree_param);
[train_results_4, ~, ~] = svmpredict(tr_label, tr_data, model, '');
[test_results_4, ~, ~] = svmpredict(te_label, te_data, model, '');

model = train_svm(tr_data_l1, tr_label_l1, te_data_l1, te_label_l1, kernel_param, C_param, gamma_param, coef0_param, degree_param);
[train_results_5, ~, ~] = svmpredict(tr_label_l1, tr_data_l1, model, '');
[test_results_5, ~, ~] = svmpredict(te_label_l1, te_data_l1, model, '');


model = train_svm(tr_data_hellinger, tr_label_hellinger, te_data_hellinger, te_label_hellinger, kernel_param, C_param, gamma_param, coef0_param, degree_param);      
[train_results_6, ~, ~] = svmpredict(tr_label_hellinger, tr_data_hellinger, model, '');
[test_results_6, ~, ~] = svmpredict(te_label_hellinger, te_data_hellinger, model, '');  





%Linear Kernel 
kernel_param = 0;

model7 = train_svm(tr_data, tr_label, te_data, te_label, kernel_param, C_param, gamma_param, coef0_param, degree_param);
[train_results_7, ~, ~] = svmpredict(tr_label, tr_data, model7, '');
[test_results_7, ~, ~] = svmpredict(te_label, te_data, model7, '');

model = train_svm(tr_data_l1, tr_label_l1, te_data_l1, te_label_l1, kernel_param, C_param, gamma_param, coef0_param, degree_param);
[train_results_8, ~, ~] = svmpredict(tr_label_l1, tr_data_l1, model, '');
[test_results_8, ~, ~] = svmpredict(te_label_l1, te_data_l1, model, '');


model = train_svm(tr_data_hellinger, tr_label_hellinger, te_data_hellinger, te_label_hellinger, kernel_param, C_param, gamma_param, coef0_param, degree_param);      
[train_results_9, ~, ~] = svmpredict(tr_label_hellinger, tr_data_hellinger, model, '');
[test_results_9, ~, ~] = svmpredict(te_label_hellinger, te_data_hellinger, model, '');        




% Different polynomial Kernels
C_param = 100;
gamma_param = 0.1;
coef0_param = 0;
degree_param = 2;
kernel_param = 1; % Polynomial kernel

model = train_svm(tr_data, tr_label, te_data, te_label, kernel_param, C_param, gamma_param, coef0_param, degree_param);
[train_results_10, ~, ~] = svmpredict(tr_label, tr_data, model, '');
[test_results_10, ~, ~] = svmpredict(te_label, te_data, model, '');

model = train_svm(tr_data_l1, tr_label_l1, te_data_l1, te_label_l1, kernel_param, C_param, gamma_param, coef0_param, degree_param);
[train_results_11, ~, ~] = svmpredict(tr_label_l1, tr_data_l1, model, '');
[test_results_11, ~, ~] = svmpredict(te_label_l1, te_data_l1, model, '');


model = train_svm(tr_data_hellinger, tr_label_hellinger, te_data_hellinger, te_label_hellinger, kernel_param, C_param, gamma_param, coef0_param, degree_param);      
[train_results_12, ~, ~] = svmpredict(tr_label_hellinger, tr_data_hellinger, model, '');
[test_results_12, ~, ~] = svmpredict(te_label_hellinger, te_data_hellinger, model, '');   


C_param = 10;
gamma_param = 0.1;
coef0_param = 0;
degree_param = 3;
kernel_param = 1; % Polynomial kernel

 model = train_svm(tr_data, tr_label, te_data, te_label, kernel_param, C_param, gamma_param, coef0_param, degree_param);
[train_results_13, ~, ~] = svmpredict(tr_label, tr_data, model, '');
[test_results_13, ~, ~] = svmpredict(te_label, te_data, model, '');

model = train_svm(tr_data_l1, tr_label_l1, te_data_l1, te_label_l1, kernel_param, C_param, gamma_param, coef0_param, degree_param);
[train_results_14, ~, ~] = svmpredict(tr_label_l1, tr_data_l1, model, '');
[test_results_14, ~, ~] = svmpredict(te_label_l1, te_data_l1, model, '');


model = train_svm(tr_data_hellinger, tr_label_hellinger, te_data_hellinger, te_label_hellinger, kernel_param, C_param, gamma_param, coef0_param, degree_param);     
[train_results_15, ~, ~] = svmpredict(tr_label_hellinger, tr_data_hellinger, model, '');
[test_results_15, ~, ~] = svmpredict(te_label_hellinger, te_data_hellinger, model, '');   


C_param = 10000;
gamma_param = 0.01;
coef0_param = 0;
degree_param = 2;
kernel_param = 1; % Polynomial kernel

 model = train_svm(tr_data, tr_label, te_data, te_label, kernel_param, C_param, gamma_param, coef0_param, degree_param);
[train_results_16, ~, ~] = svmpredict(tr_label, tr_data, model, '');
[test_results_16, ~, ~] = svmpredict(te_label, te_data, model, '');   

model = train_svm(tr_data_l1, tr_label_l1, te_data_l1, te_label_l1, kernel_param, C_param, gamma_param, coef0_param, degree_param);
[train_results_17, ~, ~] = svmpredict(tr_label_l1, tr_data_l1, model, '');
[test_results_17, ~, ~] = svmpredict(te_label_l1, te_data_l1, model, '');


model = train_svm(tr_data_hellinger, tr_label_hellinger, te_data_hellinger, te_label_hellinger, kernel_param, C_param, gamma_param, coef0_param, degree_param);      
[train_results_18, ~, ~] = svmpredict(tr_label_hellinger, tr_data_hellinger, model, '');
[test_results_18, ~, ~] = svmpredict(te_label_hellinger, te_data_hellinger, model, '');   



C_param = 1;
gamma_param = 0.1;
coef0_param = 0;
degree_param = 2;
kernel_param = 1; % Polynomial kernel        
 model = train_svm(tr_data, tr_label, te_data, te_label, kernel_param, C_param, gamma_param, coef0_param, degree_param);
[train_results_19, ~, ~] = svmpredict(tr_label, tr_data, model, '');
[test_results_19, ~, ~] = svmpredict(te_label, te_data, model, '');         

model = train_svm(tr_data_l1, tr_label_l1, te_data_l1, te_label_l1, kernel_param, C_param, gamma_param, coef0_param, degree_param);
[train_results_20, ~, ~] = svmpredict(tr_label_l1, tr_data_l1, model, '');
[test_results_20, ~, ~] = svmpredict(te_label_l1, te_data_l1, model, '');


model = train_svm(tr_data_hellinger, tr_label_hellinger, te_data_hellinger, te_label_hellinger, kernel_param, C_param, gamma_param, coef0_param, degree_param);      
[train_results_21, ~, ~] = svmpredict(tr_label_hellinger, tr_data_hellinger, model, '');
[test_results_21, ~, ~] = svmpredict(te_label_hellinger, te_data_hellinger, model, '');   



% Adaboost
% Save all weak learners together - pre-processing for adaboost
dataFeatures = [train_results_1 train_results_2 train_results_3 train_results_4 train_results_5 train_results_6 train_results_7 train_results_8 train_results_9 train_results_10 train_results_11 train_results_12 train_results_13 train_results_14 train_results_15 train_results_16 train_results_17 train_results_18 train_results_19 train_results_20 train_results_21];
dataclass = tr_label;
testdata = [test_results_1 test_results_2 test_results_3 test_results_4 test_results_5 test_results_6 test_results_7 test_results_8 test_results_9 test_results_10 test_results_11 test_results_12 test_results_13 test_results_14 test_results_15 test_results_16 test_results_17 test_results_18 test_results_19 test_results_20 test_results_21];  

% Run adaboost
[~,model]=adaboost('train',dataFeatures,dataclass,500);        
testclass=adaboost('apply',testdata,model);

        
        acc = 100*((length(find(testclass==te_label)))/(length(te_label)));
        avg_acc = avg_acc + acc;
    end
    avg_acc = avg_acc /3;
    fprintf('Accuracy achieved is %f\n', avg_acc);
end

